﻿<sap:ActivityDesigner x:Class="MyData.Activities.Designers.ConnectionActivityDesigner"
    xmlns:s="clr-namespace:System;assembly=mscorlib" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation" 
    xmlns:net="clr-namespace:System.Net;assembly=System" 
    xmlns:sql="clr-namespace:System.Data.SqlClient;assembly=System.Data" Collapsible="True">
    <sap:ActivityDesigner.Resources>
        <sapc:ArgumentToExpressionConverter 
                x:Key="ArgumentToExpressionConverter" />

        <DataTemplate x:Key="ShowAsCollapsed">
            <TextBlock>Expand to edit properties</TextBlock>
        </DataTemplate>
        <DataTemplate x:Key="ShowAsExpanded">
            <Grid>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>

                <TextBlock Text="Credentials" Grid.Row ="0" Grid.Column="1"
            HorizontalAlignment="Left" VerticalAlignment="Center" />

                <sapv:ExpressionTextBox HintText="Credential" 
            Grid.Row ="0" Grid.Column="2" MaxWidth="150" MinWidth="150" Margin="5"
            OwnerActivity="{Binding Path=ModelItem}"
            Expression="{Binding Path=ModelItem.NetworkCredential, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
            ExpressionType="net:ICredentials" GotFocus="ExpressionTextBox_GotFocus" />


                <TextBlock Text="Data Source" Grid.Row ="1" Grid.Column="1"
            HorizontalAlignment="Left" VerticalAlignment="Center" />

                <sapv:ExpressionTextBox HintText="Data Source" 
            Grid.Row ="1" Grid.Column="2" MaxWidth="150" MinWidth="150" Margin="5"
            OwnerActivity="{Binding Path=ModelItem}"
            Expression="{Binding Path=ModelItem.DataSource, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
            ExpressionType="s:String" GotFocus="ExpressionTextBox_GotFocus" />

                <TextBlock Text="Initial Catalog" Grid.Row ="2" Grid.Column="1"
            HorizontalAlignment="Left" VerticalAlignment="Center" />

                <sapv:ExpressionTextBox HintText="Initial Catalog" 
            Grid.Row ="2" Grid.Column="2" MaxWidth="150" MinWidth="150" Margin="5"
            OwnerActivity="{Binding Path=ModelItem}"
            Expression="{Binding Path=ModelItem.InitialCatalog, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=In }"
            ExpressionType="s:String" GotFocus="ExpressionTextBox_GotFocus" />


                <TextBlock Text="=" TextAlignment="Right" Grid.Column="1" Grid.Row="3"  Margin="5"/>
                <sapv:ExpressionTextBox HintText="SqlConnectionBuilder" 
            Grid.Row ="3" Grid.Column="2" Margin="4" MaxWidth="200" MinWidth="150"
            OwnerActivity="{Binding Path=ModelItem}"
            Expression="{Binding Path=ModelItem.SqlConnectionBuilder, Mode=TwoWay, 
                Converter={StaticResource ArgumentToExpressionConverter}, 
                ConverterParameter=Out }"
            ExpressionType="sql:SqlConnectionStringBuilder" GotFocus="ExpressionTextBox_GotFocus"
            UseLocationExpression="True" BorderBrush="#FF0000DE" BorderThickness="2">

                    <sapv:ExpressionTextBox.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black" Offset="0" />
                            <GradientStop Color="White" Offset="1" />
                            <GradientStop Color="#005050FF" Offset="0" />
                            <GradientStop Color="#6A9999FF" Offset="0" />
                            <GradientStop Color="#C8D9D9FF" Offset="0" />
                        </LinearGradientBrush>
                    </sapv:ExpressionTextBox.Background>
                </sapv:ExpressionTextBox>
            </Grid>
        </DataTemplate>

        <Style x:Key="StyleWithCollapse" TargetType="{x:Type ContentPresenter}">
            <Setter Property="ContentTemplate" 
                Value="{DynamicResource ShowAsExpanded}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=ShowExpanded}" Value="False">
                    <Setter Property="ContentTemplate" 
                        Value="{DynamicResource ShowAsCollapsed }"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </sap:ActivityDesigner.Resources>

    <sap:ActivityDesigner.Icon>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <ImageDrawing>
                    <ImageDrawing.Rect>
                        <Rect Location="0,0"  Size="16,16" />
                    </ImageDrawing.Rect>
                    <ImageDrawing.ImageSource>

                        <BitmapImage UriSource="ConnectionBuilderActivity.png"/>
                    </ImageDrawing.ImageSource>
                </ImageDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </sap:ActivityDesigner.Icon>

    <Grid>
        <ContentPresenter Style="{DynamicResource StyleWithCollapse}" 
            Content="{Binding}" />
    </Grid>
</sap:ActivityDesigner>
